using System;
using System.Collections.Generic;
using System.Text;
using CodeFactory.IDAL;

namespace CodeFactory.Access
{
    public class AccessProvider : IProvider
    {
        private AccessHelper dbHelper;
        private AccessAdapter dataAdapter;
        private string connectionString;

        public IDbHelper DbHelper
        {
            get
            {
                if (string.IsNullOrEmpty(this.connectionString))
                    throw new DALException("can't init access database connectionstring.");
                if (this.dbHelper == null)
                {
                    this.dbHelper = new AccessHelper(connectionString);
                }
                return this.dbHelper;
            }
        }

        public IDataAdapter DataAdapter
        {
            get
            {
                if (this.dataAdapter == null)
                {
                    this.dataAdapter = new AccessAdapter(this.DbHelper);
                }
                return this.dataAdapter;
            }
        }

        public string ConnectionString
        {
            get { return this.connectionString; }
            set { this.connectionString = value; }
        }

        public AccessProvider()
        {
        }

        public string BuildConnectionString(ConnectionInfo connInfo)
        {
            return string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}", connInfo.DbPath);
        }
    }
}
